<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=s, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let num =0;
        let myevent = new EventTarget();

        function fn1(cb){
            setTimeout(()=>{
                console.log('fn1')
                cb&&cb();
                num++;
                myevent.dispatchEvent(new CustomEvent('event'+num));
            },1000)
        }

        function fn2(cb){
            setTimeout(() => {
                console.log("fn2");
                cb && cb();
                num++;
                 // 触发自定义事件 event2
                myevent.dispatchEvent(new CustomEvent("event"+num));
            }, 1000);
        }

        function fn3(cb){
            setTimeout(() => {
                console.log("fn3");
                cb && cb();
                num++;
                 // 触发自定义事件 event3
                myevent.dispatchEvent(new CustomEvent("event"+num));
            }, 1000);
        }

        fn1();
        myevent.addEventListener("event1",function(){
            console.log('fn1执行完了')
            fn2()
        })

        myevent.addEventListener("event2",function(){
            console.log('fn1执行完了')
            fn3()
        })

        myevent.addEventListener("event3",function(){
            console.log('fn3执行完了')
            
        })
    </script>
</body>
</html>